// renderSlots.ts
import { h, Component } from 'vue';
import { ElRadio, ElCheckbox, ElOption } from 'element-plus';
import { itemType } from '../_assets/types';
 
// 定义一个映射表，将类型映射到对应的组件和渲染逻辑
const componentMap: Record<string, Component> = {
  radio: ElRadio,
  checkbox: ElCheckbox,
  select: ElOption,
};

// 渲染插槽内容
export function renderSlots(type: itemType, formOptions: any) {
  if (!type && !formOptions) return null;
  
  const validType = type as keyof typeof componentMap;
  const Comp = componentMap[validType];
  if (!Comp) return null;
  
  return formOptions.map((option: { value: string; label: string }) =>
    h(Comp, { key: option.value, value: option.value, label: option.label })
  );
}